from django.db import models


class XhsCreator(models.Model):
    user_id = models.CharField(max_length=64, verbose_name='用户ID')
    nickname = models.CharField(max_length=64, null=True, blank=True, verbose_name='用户昵称')
    avatar = models.CharField(max_length=255, null=True, blank=True, verbose_name='用户头像地址')
    ip_location = models.CharField(max_length=255, null=True, blank=True, verbose_name='评论时的IP地址')
    add_ts = models.BigIntegerField(verbose_name='记录添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='记录最后修改时间戳')
    desc = models.TextField(verbose_name='用户描述')
    gender = models.CharField(max_length=2, null=True, blank=True, verbose_name='性别')
    follows = models.CharField(max_length=16, null=True, blank=True, verbose_name='关注数')
    fans = models.CharField(max_length=16, null=True, blank=True, verbose_name='粉丝数')
    interaction = models.CharField(max_length=16, null=True, blank=True, verbose_name='获赞和收藏数')
    tag_list = models.TextField(verbose_name='标签列表')
    task_id = models.CharField(max_length=255, verbose_name='任务ID', null=True, blank=True)

    class Meta:
        db_table = 'xhs_creator'
        verbose_name = '小红书博主'


class XhsNote(models.Model):
    user_id = models.CharField(max_length=64, verbose_name='用户ID')
    nickname = models.CharField(max_length=64, null=True, blank=True, verbose_name='用户昵称')
    avatar = models.CharField(max_length=255, null=True, blank=True, verbose_name='用户头像地址')
    ip_location = models.CharField(max_length=255, null=True, blank=True, verbose_name='评论时的IP地址')
    add_ts = models.BigIntegerField(verbose_name='记录添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='记录最后修改时间戳')
    note_id = models.CharField(max_length=64, verbose_name='笔记ID', unique=True)
    type = models.CharField(max_length=16, null=True, blank=True, verbose_name='笔记类型(normal | video)')
    title = models.CharField(max_length=255, null=True, blank=True, verbose_name='笔记标题')
    desc = models.TextField(verbose_name='笔记描述')
    video_url = models.TextField(verbose_name='视频地址')
    time = models.BigIntegerField(verbose_name='笔记发布时间戳')
    last_update_time = models.BigIntegerField(verbose_name='笔记最后更新时间戳')
    liked_count = models.CharField(max_length=50, null=True, blank=True, verbose_name='笔记点赞数')
    collected_count = models.CharField(max_length=50, null=True, blank=True, verbose_name='笔记收藏数')
    comment_count = models.CharField(max_length=50, null=True, blank=True, verbose_name='笔记评论数')
    share_count = models.CharField(max_length=50, null=True, blank=True, verbose_name='笔记分享数')
    image_list = models.TextField(verbose_name='笔记封面图片列表')
    tag_list = models.TextField(verbose_name='标签列表')
    note_url = models.CharField(max_length=255, null=True, blank=True, verbose_name='笔记详情页的URL')
    source_keyword = models.CharField(max_length=255, default='', verbose_name='搜索来源关键字')
    task_id = models.CharField(max_length=255, verbose_name='任务ID', null=True, blank=True)

    class Meta:
        db_table = 'xhs_note'
        verbose_name = '小红书笔记'
        indexes = [
            models.Index(fields=['note_id'], name='idx_xhs_note_note_id_209457'),
            models.Index(fields=['time'], name='idx_xhs_note_time_eaa910'),
        ]


class XhsNoteComment(models.Model):
    user_id = models.CharField(max_length=64, verbose_name='用户ID')
    nickname = models.CharField(max_length=64, null=True, blank=True, verbose_name='用户昵称')
    avatar = models.CharField(max_length=255, null=True, blank=True, verbose_name='用户头像地址')
    ip_location = models.CharField(max_length=255, null=True, blank=True, verbose_name='评论时的IP地址')
    add_ts = models.BigIntegerField(verbose_name='记录添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='记录最后修改时间戳')
    comment_id = models.CharField(max_length=64, verbose_name='评论ID')
    create_time = models.BigIntegerField(verbose_name='评论时间戳')
    note_id = models.ForeignKey(
        XhsNote,
        to_field='note_id',
        db_column='note_id',
        on_delete=models.CASCADE,
        related_name='comments',
        verbose_name='笔记关联',
        null=True,
        blank=True,
    )
    content = models.TextField(verbose_name='评论内容')
    sub_comment_count = models.IntegerField(verbose_name='子评论数量')
    pictures = models.CharField(max_length=512, null=True, blank=True, verbose_name='图片')
    parent_comment_id = models.CharField(max_length=64, null=True, blank=True, verbose_name='父评论ID')
    like_count = models.IntegerField(default=0, verbose_name='点赞数')
    note_url = models.CharField(max_length=255, null=True, blank=True, verbose_name='笔记详情页的URL')

    class Meta:
        db_table = 'xhs_note_comment'
        verbose_name = '小红书笔记评论'
        indexes = [
            models.Index(fields=['comment_id'], name='idx_xhs_note_co_comment_8e8349'),
            models.Index(fields=['create_time'], name='idx_xhs_note_co_create__204f8d'),
        ]
